package com.person.yhzs.wxPayV3;

import com.person.yhzs.common.ReturnData;
import com.person.yhzs.user.service.UserService;
import com.person.yhzs.wxPayV3.service.WXPayV3Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author luolin
 * @Description
 * @createTime 2022年07月04日 14:41:00
 */
@RestController
@Api(tags = "微信支付V3")
@RequestMapping("wxPay/v3")
public class WXPayV3Controller {
    @Resource
    private UserService userService;

    @Resource
    private WXPayV3Service wxPayV3Service;

    /**
     * @Description 微信支付成功
     * @Author luolin
     * @Date 2022/6/24 14:40
     **/
    @ApiOperation(value = "微信支付成功",notes = "微信支付成功接口")
    @PostMapping("success")
    public ReturnData paySuccess(){
        return  null;
    }

    @ApiOperation(value = "微信登录", notes = "微信登录接口")
    @GetMapping(value = "/login/{code}")
    public ReturnData payWXLogin(@PathVariable String code){
        Map<String,Object> login = userService.wxLogin(code);
        return ReturnData.ok(login);
    }

    @ApiOperation(value = "微信支付下单", notes = "微信支付下单接口")
    @PostMapping("/order/{openId}")
    public ReturnData payWXOrder(HttpServletRequest request, @PathVariable String openId) throws Exception {

        Map<String, Object> resultMap = wxPayV3Service.payWXOrder(request, openId);

        return ReturnData.ok(resultMap);
    }
}
